<div style="clear:both;"></div>
<?php use_helper('Pagination'); ?>
<?php use_helper('Date');?>
<?php
if(isset($config['extraTemplates'])){
	foreach($config['extraTemplates'] as $template){
		include_partial($template, array()); 
	}
}
?>

<?php 
   	$actualnbPosts = $config['nbResults'];   	
   	$hide = $config['hide'];
	if(!isset($hide)) $hide = array();
	$functionParams = '\''.$view.'\','.$actualPage.','.$actualnbPosts;
?>
<script type="text/javascript">
	function refresh(view, page, nbPosts, orderField){
		document.getElementById('updateView').style.display = 'block';
		
		$('#liste').fadeTo("fast", 0.5);
		
		var xhr = getXmlHttpRequest2();
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200)
				{
				textResponse = xhr.responseText;
				document.getElementById('updateView').style.display = 'none';
				document.getElementById('liste').innerHTML = textResponse;

				$("a.dmdPreview").fancybox({
					type: 'ajax',
					maxWidth	: 800,
					maxHeight	: 600,
					fitToView	: false,
					autoSize	: false,
					closeClick	: false,
					openEffect	: 'elastic',
					closeEffect	: 'elastic'
				});			
				$("#viewConfigButton").fancybox({
					type: 'ajax',
					maxWidth	: 500,
					maxHeight	: 600,
					fitToView	: false,
					autoSize	: false,
					closeClick	: false,
					openEffect	: 'elastic',
					closeEffect	: 'elastic'
					//afterClose	: function() {
					//	refresh(<?php echo $functionParams ?>);
				    //    return;
				    //}
				});		
				$('#liste').fadeTo("fast",1);
				
			}
		};
		xhr.open("POST","<?php print url_for('ajax/getListDossiers'); ?>",true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.setRequestHeader('X_REQUESTED_WITH','XMLHttpRequest');
		xhr.send("moduleRef=<?php echo $sf_request->getParameter('module')?>&actionRef=<?php echo $sf_request->getParameter('action')?>" + "&view="+view+"&page="+page+"&nbPosts="+nbPosts+"&order="+orderField);
		document.getElementById('refreshFunctionParams').value = '\''+view+'\',1,'+nbPosts +',\'' + orderField +'\'';
	
	}

</script>

<?php include_partial('search/searchBar',array( 'moduleRef' => $sf_request->getParameter('module'), 'actionRef' => $sf_request->getParameter('action'), 'className'=>$objDef->className, 'ajaxSearch'=>true))?>
<?php $routeName = sfContext::getInstance()->getRouting()->getCurrentInternalUri(false) ?>
<input type="hidden" id="refreshFunctionParams" name="refreshFunctionParams" value="<?php echo '\''.$view.'\','.$actualPage.','.$actualnbPosts.',\''.$order.'\'';?>,''"></input>
	<?php if ($sf_user->hasFlash('warning')): ?>
	<div id="warning" class="errorDisplay" style = "display:block;">
		<h3><?php print $sf_user->getFlash('warning'); ?></h3>
	</div>
<?php endif;?>
<?php if ($sf_user->hasFlash('userMsg')): ?>
	<div id="userMsg" class="msgDisplay" style="display: block;">
		<h3><?php print $sf_user->getFlash('userMsg'); ?></h3>
	</div>
<?php endif;?>
<br />

	<div id="updateView" style="display:none;text-align:center;">
	<img alt="<?php echo __('wait please...')?> '" src="/images/ajax-loader.gif" />
	</div>	
	<div style="width: 100%; height: 40px;"></div>
	<div id="liste"><table>
	<?php echo $objDef->renderListHeader($hide,'table',true,true,$functionParams);?>
		<tbody id=tableContent />
		</table>
	</div>
	
	<?php $defaultOrderCol = 'datedemande*desc';;
		  echo '<div id="restaurerLink"><a href="javascript: refresh(\''.$view.'\', 1, '.sfConfig::get('app_posts_number_per_page', 10).',\''.$defaultOrderCol.'\' );">'.__('Restore view default values').'</a></div>';?>

<script type="text/javascript">
$(document).ready(function(){
		addFilters();
});
</script>
